package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 9:23
 */
@Service
public class DtsCommentServiceImpl implements DtsCommentService {

    @Autowired
    private DtsCommentMapper dtsCommentMapper;

    /**
     * 查询
     * @param userId
     * @param valueId
     * @param sort
     * @param order
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<DtsComment> findListByQuery(String userId, String valueId, String sort, String order, Integer page, Integer limit) {
        return dtsCommentMapper.selectPage(new Page(page,limit),
                new QueryWrapper<DtsComment>()
                        .eq(!StringUtils.isEmpty(userId),"user-id",userId)
                        .eq(!StringUtils.isEmpty(valueId),"value_id",valueId)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort)
        );
    }

    /**
     * 评论删除
     * @param dtsComment
     * @return
     */
    @Override
    public DtsComment delete(DtsComment dtsComment) {
        dtsCommentMapper.deleteById(dtsComment);
        return dtsComment;
    }


}
